package ig.da.abs;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public abstract class AbstractBasicDTO {

	/**
	 * Retorna la descripcion del elemento cargado
	 * @return
	 */
	public String getDescripcion(){
		Method[] method =  this.getClass().getDeclaredMethods();
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < method.length; i++) {
			String name = method[i].getName();
			if(name .startsWith("get")){
				try {
					Object obj = method[i].invoke(this);
					String value = (obj == null || obj.toString().trim().isEmpty()) ? "-" : obj.toString().trim();
					name = name.substring(3).trim();
					value = name + ":" + value;
					//value = name.substring(3).split("_")[0] + " : " + value;
					//value = value.trim().length()<32 ? (value).substring(0, 32) : value;
					builder.append( "[" + value+"]\n" );
				} catch (Exception e) {
					builder.append( "[" + name + ":Err]\n" );
					e.printStackTrace();
				}
			}
		}
		return builder.toString();
	}
	
	/**
	 * Set de la descipcion
	 * @param descripcio
	 */
	public void setDescripcion(String descripcio){

	}
}
